package com.wenjie.controller.sys;

import cn.hutool.json.JSONObject;
import com.wenjie.original.entity.vo.SysDbTable.SysDbTableUpOrAddVo;
import com.wenjie.original.entity.vo.SysDbTable.SysDbTableVo;
import com.wenjie.original.service.ISysDbTableService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api("后台用户管理")
@RestController
@RequestMapping("/api/sysDbTable")
public class SysDbTableController {
    @Autowired
    private ISysDbTableService sysDbTableService;

    @ApiOperation("查询接口")
    @PostMapping("/list")
    public List<SysDbTableVo.ResVo> list() {
        return sysDbTableService.cusListAll();
    }

    @ApiOperation("同步表接口")
    @PostMapping("/sync")
    public void sync(@RequestBody JSONObject jsonObject) {
        sysDbTableService.sync(jsonObject.getStr("tableName"));
    }

    @ApiOperation("同步表接口")
    @PostMapping("/syncAll")
    public void syncAll() {
        sysDbTableService.syncAll();
    }


    @ApiOperation("批量同步表接口")
    @PostMapping("/syncAllAndField")
    public void syncAllAndField() {
        sysDbTableService.syncAllAndField();
    }

    @ApiOperation("添加接口")
    @PostMapping("/add")
    public void add(@RequestBody @Validated SysDbTableUpOrAddVo.AddVo addVo) {
        sysDbTableService.save(addVo);
    }

    @ApiOperation("修改接口")
    @PostMapping("/up")
    public void up(@RequestBody @Validated SysDbTableUpOrAddVo.UpVo upVo) {
        sysDbTableService.custUpdateById(upVo);
    }

    @ApiOperation("删除接口")
    @PostMapping("/del")
    public void del(@RequestBody @Validated Long id) {
        sysDbTableService.cusRemoveByid(id);
    }

}
